//
//  GUIcontroller.h
//  cocoaUDPServer
//
//  Created by Matt Roman on 7/16/08.
//  Copyright 2008 University of Oklahoma. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "NetServer.h"
#import <IOKit/pwr_mgt/IOPMLib.h>
#import <IOKit/IOMessage.h>
#import "roverSide.h"
#import "definitions.h"
#import "simController.h"

@interface botSimulator : NSObject {
	IBOutlet NSTextField	*textToSend;
	IBOutlet NSTextView		*textView;
	NetServer				*server;
	int						sendWhat;
	NSMutableData			*netData;
	NSMutableString			*netString;
	IBOutlet NSWindow		*mainWindow;
	IBOutlet NSTextField	*StateOut;
	IBOutlet NSTextField	*ErrorOut;
	
	IBOutlet simController	*sim;
	
	roverProperties			sr2;
	
	int						wpCount;
	
	bool					laserPower;
	
	// compass
	float				heading,pitch,roll;
	int					alarm;
	// lasers
	BOOL				requestLaserUpdate;
	laserScanner		bodyLaser;
	int					bodyLaserDirection;
	laserScanner		panelLaser;
	int					panelLaserDirection;
	laserScanner		profileLaser;
	int					profileLaserDirection;
	// XBC
	int					rightEncoder,leftEncoder;
	int					rightSpeed,leftSpeed;
	int					motorCurrent,electroCurrent,panelCurrent;
	int					batteryVoltage;
	int					xbcTime;
	int					pan,tilt;
	int					relays;
	//SporTrakGPS
	LatLonCoord			gpsCoordinates;
	
	NSThread				*sensorUpdateThread;
	BOOL					logging;
	NSString				*logFile;
	NSFileHandle			*logHandle;
	
	BOOL					stop;
	BOOL					Joystick;
	BOOL					updateRelays;
	BOOL					incommingDataList;
	BOOL					incommingGoTo;
	BOOL					incommingPosition;
	BOOL					incommingKonstants;
	BOOL					incommingTerrainMap;

	// configuration file
	NSFileHandle			*configFile;
	NSString				*configFileName;
	
	// simulation romote drive control
	BOOL					driveControl; // CC08 has rover control? or simulation has control
}

// XBC
// send motor speeds to xbc and reset encoders and switch relays
// read in voltage currents and motor positions and time
// Compass
// read in heading pitch and roll
// GPS
// read in lat long coordinates
// Lasers
// read in an array of distances based on shape of scan parameters
- (void)computeLaserConstants:(laserScanner*)scanner;

- (BOOL)startServer;
- (void)startupBodyLaser;
- (void)startupPanelLaser;
- (void)startupProfileLaser;

// network function calls
- (void)SensorsSetup;
- (void)SensorStatus;
- (void)Konstants;
- (void)Stop;
- (void)Run;
- (void)JoystickOn;
- (void)JoystickOff;
- (void)JoystickForward;
- (void)JoystickBackward;
- (void)JoystickLeft;
- (void)JoystickRight;
- (void)Sleeping;
- (void)Sleep;
- (void)Waking;
- (void)Wake;
- (void)PowerUpLasers;
- (void)PowerDownLasers;
- (void)ConnectXBC;
- (void)ConnectGPS;
- (void)ConnectCompass;
- (void)SystemShutdown;
- (void)SystemRestart;
- (void)RestartApp;
- (void)ResetRover;
- (void)SetRover;
- (void)PlanList;
- (void)ClearWaypoints;
- (void)GoToWaypoint;
- (void)UpdateKonstants;
- (void)WaypointFinished;
- (void)WaypointSkipped;
- (void)WhatWaypoint;
- (void)Simulation;

- (IBAction)sendOverServer:(id)sender;
- (IBAction)sendOwnAction:(id)sender;
- (IBAction)beamSwitch:(id)sender;
- (IBAction)waypointSim:(id)sender;
- (IBAction)remoteControlSelect:(id)sender;
@end
